package com.anhuanjia.tools.eao.controller;

import java.util.UUID;

import org.springframework.util.StringUtils;

import com.anhuanjia.tools.eao.bean.EaoPublicityAudit;
import com.efastsoft.framework.UIFacade;
import com.efastsoft.framework.annotation.Alias;
import com.efastsoft.framework.annotation.Priv;
import com.efastsoft.framework.annotation.Priv.LoginType;
import com.efastsoft.framework.data.DataTable;
import com.efastsoft.framework.data.Q;
import com.efastsoft.framework.data.Transaction;

/**
 * 公示审核表操作
 * 
 * @author Administrator
 *
 */

@Alias(value = "publicityAuditUI")
public class PublicityAuditUI extends UIFacade {

	@Priv(loginType = LoginType.Member)
	public void saveOrUpdate() {
		String id = $V("Id");
		String is = $V("IsAudit");
		Transaction transaction = new Transaction();
		if (StringUtils.isEmpty(id)) {
			EaoPublicityAudit publicityAudit = new EaoPublicityAudit();
			publicityAudit.setId(UUID.randomUUID().toString());
			publicityAudit.setIsAudit(is);// 是否需要审核(0否1是)
			transaction.insert(publicityAudit);
		} else {
			DataTable dt = new Q("select * from eao_publicity_audit where id = ? ", id).fetch();
			if (dt.getRowCount() > 0) {
				EaoPublicityAudit publicityAudit = new EaoPublicityAudit();
				publicityAudit.setValue(dt.get(0));
				publicityAudit.setIsAudit(is);// 是否需要审核(0否1是)
				transaction.update(publicityAudit);
			} else {
				EaoPublicityAudit publicityAudit = new EaoPublicityAudit();
				publicityAudit.setId(UUID.randomUUID().toString());
				publicityAudit.setIsAudit(is);// 是否需要审核(0否1是)
				transaction.insert(publicityAudit);
			}
		}
		if(transaction.commit()) {
			s("公示审核状态更新成功");
		} else {
			f("公示审核状态更新失败");
		}

	}
	
	@Priv(loginType = LoginType.Member)
	public void findBy() {
		DataTable dt = new Q("select * from eao_publicity_audit ").fetch();
		EaoPublicityAudit publicityAudit = new EaoPublicityAudit();
		publicityAudit.setValue(dt.get(0));
		this.Response.put("publicityAudit", publicityAudit);
		
	}

}
